package com.hk.webapp.controller.admin;

import com.hk.webapp.bean.SiteSetting;
import com.hk.webapp.service.SiteSettingService;
import com.hk.webapp.vo.ResultVo;
import com.hk.webapp.vo.SiteSettingVo;
import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
public class SiteSettingController extends AdminBaseController {

    @Resource
    private SiteSettingService siteSettingService;

    @PostMapping("/SiteSetting/GetInfo")
    public ResultVo getInfo(){

        List<SiteSetting> list=siteSettingService.getEntityList();

        HashMap<String,Object> map= Maps.newHashMap();
        for (SiteSetting seting : list) {
            map.put(seting.getKey(),seting.getValue());
        }
        return ResultVo.createBySuccessData(map);
    }
    @PostMapping("/SiteSetting/SetInfo")
    public ResultVo setInfo(@RequestBody SiteSettingVo vo){

        Integer count= siteSettingService.updateValue(vo);
        return ResultVo.createBySuccessData(count);
    }
}
